package com.pinxixi.goods.controller;

import com.pinxixi.api.goods.GoodsControllerApi;
import com.pinxixi.framework.domain.goods.Goods;
import com.pinxixi.framework.domain.goods.ext.GoodsEntity;
import com.pinxixi.framework.model.response.ListResponseResult;
import com.pinxixi.framework.model.response.QueryResponseResult;
import com.pinxixi.framework.model.response.ResponseResult;
import com.pinxixi.goods.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/goods")
public class GoodsController implements GoodsControllerApi {

    @Autowired
    private GoodsService goodsService;


    @Override
    @PostMapping("/save")
    public ResponseResult save(@RequestBody GoodsEntity goodsEntity) {
        return goodsService.save(goodsEntity);
    }

    @Override
    @GetMapping("/findPage")
    public ListResponseResult<Goods> findPage() {
        return goodsService.findPage();
    }

    @Override
    @PostMapping("/commitApply")
    public ResponseResult commitApply(@RequestBody Long[] ids) {
        return goodsService.commitApply(ids);
    }

    @Override
    @PostMapping("/goodsApply/{status}")
    public ResponseResult goodsApply(@RequestBody Long[] ids,@PathVariable("status") Integer status) throws Exception {
        return goodsService.goodsApply(ids,status);
    }

    @Override
    @GetMapping("/findOne/{id}")
    public QueryResponseResult findOne(@PathVariable("id") Long id) {
        return goodsService.findOne(id);
    }

    @Override
    @GetMapping("/goodsCache/{spuid}/{skuid}")
    @CrossOrigin(origins = "*")
    public QueryResponseResult goodsCache(@PathVariable("spuid") Long spuid,@PathVariable("skuid") Long skuid) {
        return goodsService.goodsCache(spuid,skuid);
    }

}
